package org.example.springboot.service;


import org.example.springboot.entity.Teacher;
import org.example.springboot.entity.TeacherAndCourse;
import org.example.springboot.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class TeacherService {

    @Autowired
    TeacherMapper teacherMapper;

    public List<Teacher> getTeachersByPage(int pageNum, int pageSize, String username) {
        int offset = (pageNum - 1) * pageSize;
        return teacherMapper.getTeachersByPage(pageSize,offset, username);
    }

    public int getTeacherCount(String username) {
        return teacherMapper.getTeacherCount(username);
    }

    @Transactional
    public void deleteTeacherByAccount(String account) {
        teacherMapper.deleteTeacherByAccount(account);
    }

    @Transactional
    public void insertTeacher(Teacher teacher) {
        teacherMapper.insertTeacher(teacher);
    }

    public Teacher getTeacherByAccount(String account) {
        return teacherMapper.selectByAccount(account);
    }

    @Transactional
    public void updateTeacher(Teacher teacher) {
        teacherMapper.updateTeacher(teacher);
    }

    public List<Map<String, Object>> getTeacherCourseDistribution() {
        return teacherMapper.getTeacherCourseDistribution();
    }

    public List<TeacherAndCourse> getTeachersByCourse(String course) {
        return teacherMapper.findTeachersByCourse(course);
    }

    public TeacherAndCourse getTeacherAndCourseByAccount(String account ,String course) {
        return teacherMapper.selectTeacherDetail(account,course);
    }

    @Transactional
    public void updatePassword(String account, String password) {
        teacherMapper.updatePassword(account, password);
    }
}
